class Book:
    def __init__(self, title: str, author: str, isbn: str):
        self.title = title  # 书名
        self.author = author  # 作者
        self.isbn = isbn  # ISBN
        self.is_borrowed = False  # 是否被借出

    def __str__(self):
        return f"《{self.title}》 by {self.author} (ISBN: {self.isbn})"

    def apply(self):
        """借出书籍"""
        if self.is_borrowed:
            print(f"《{self.title}》已经被借出，无法再次借出。")
        else:
            self.is_borrowed = True
            print(f"《{self.title}》已成功借出。")

    def unapply(self):
        """归还书籍"""
        if not self.is_borrowed:
            print(f"《{self.title}》未被借出，无需归还。")
        else:
            self.is_borrowed = False
            print(f"《{self.title}》已成功归还。")


class Library:
    def __init__(self):
        self.available_books = []  # 可用书籍列表
        self.borrowed_books = []  # 已借出书籍列表

    def add_book(self, book: Book):
        """添加新书"""
        self.available_books.append(book)
        print(f"已添加书籍：{book}")

    def borrow_book(self, isbn: str):
        """借出书籍"""
        for book in self.available_books:
            if book.isbn == isbn:
                book.apply()  # 调用 Book 类的 apply 方法
                self.available_books.remove(book)
                self.borrowed_books.append(book)
                return
        print(f"未找到 ISBN 为 {isbn} 的书籍。")

    def return_book(self, isbn: str):
        """归还书籍"""
        for book in self.borrowed_books:
            if book.isbn == isbn:
                book.unapply()  # 调用 Book 类的 unapply 方法
                self.borrowed_books.remove(book)
                self.available_books.append(book)
                return
        print(f"未找到 ISBN 为 {isbn} 的已借出书籍。")

    def list_available_books(self):
        """列出所有可用书籍"""
        if not self.available_books:
            print("没有可用的书籍。")
        else:
            print("可用书籍：")
            for book in self.available_books:
                print(book)

    def list_borrowed_books(self):
        """列出所有已借出书籍"""
        if not self.borrowed_books:
            print("没有已借出的书籍。")
        else:
            print("已借出书籍：")
            for book in self.borrowed_books:
                print(book)